/**
 * Created by huhai on 17/6/21.
 */
var app = require('express')();
var http = require('http').Server(app);
var io = require('socket.io')(http);
var config = require('./config.js') ;
app.get('/', function(req, res){
    console.log('http request in')
    // res.sendFile(__dirname + '/index.html');
    res.end("welcome to websocket control")
});


var screenReceive = io.of('/messageCenter2');
screenReceive.on('connection', function(socket){
	socket.emit('showAction',{areaType: 'split-2' , screenIndex: 0, mediaType: 'video', mediaURL:'http://wow.techbrood.com/uploads/1705/ocean-small.webm'})
});



var touchSend = io.of('/messageCenter1');
touchSend.on('connection', function(socket){
  console.log('链接消息中心');
  socket.emit('showAction',{})

  socket.on("action", function(msg){
    console.log("收到消息", msg)
    screenReceive.emit('showAction',msg)

  })
});


var fromTOUCHscreen = io.of('/config');
fromTOUCHscreen.on('connection', function(socket){
    console.log('请求配置项');
    socket.emit('config', config);
    // socket.on("action", function(msg){
    //
    //     fromBIGscreen.emit('action',msg)
    //     socket.emit("message",'已经将指令'+msg+'传递给了大屏')
    //
    // })

});

//
// io.on('connection', function(socket){
//   console.log('a user connected');
//   socket.emit('message','this is first message');
//   socket.emit('message', 1, '2', { 3: '4', 5: new Buffer(6) });
//   socket.on('message', function(msg){
//     console.log('message: ' + msg);
//   });
// });



http.listen(3010,function(){
    console.log('listening on *:3000');
});